package com.sizu.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sizu.common.inventorydto.DoDto;
import com.sizu.common.vo.ResultEntity;
import com.sizu.entity.TDamageListGoods;
import com.sizu.entity.TDo;
import com.sizu.entity.TOverflowListGoods;
import com.sizu.service.impl.TDamageListGoodsServiceImpl;
import com.sizu.service.impl.TDoServiceImpl;
import com.sizu.service.impl.TOverflowListGoodsServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 柳旦
 * @since 2020-03-16
 */
@RestController
@RequestMapping("/inventory/tDo")
public class TDoController {

    @Autowired
    private TDoServiceImpl tDoServiceImpl;
    
    @Autowired
    private TOverflowListGoodsServiceImpl tOverflowListGoodsServiceImpl;

    @Autowired
    private TDamageListGoodsServiceImpl tDamageListGoodsServiceImpl;

    //查询所有的单号（包括报损订单   报溢订单）
    @RequestMapping("/list")
    public ResultEntity list(DoDto doDto){
        Wrapper<TDo> wrapper = new EntityWrapper<TDo>();
        if(StringUtils.isBlank(doDto.getStyle())){
            List<TDo> tDos = tDoServiceImpl.selectList(wrapper);
            return ResultEntity.ok(tDos);
        }
        wrapper.eq("style",doDto.getStyle());
        wrapper.gt("do_date",doDto.getStartTime());
        wrapper.lt("do_date",doDto.getEndTime());
        List<TDo> tDos1 = tDoServiceImpl.selectList(wrapper);
        return ResultEntity.ok(tDos1);
    }

    //根据进货id查询出所有的商品
    @RequestMapping("/goodsList")
    public ResultEntity goodsList(Integer id,String style){
        if(style.equals("报溢单")){
            Wrapper<TOverflowListGoods> wrapper = new EntityWrapper<TOverflowListGoods>();
            wrapper.eq("overflow_list_id",id);
            List<TOverflowListGoods> tOverflowListGoods = tOverflowListGoodsServiceImpl.selectList(wrapper);
            return ResultEntity.ok(tOverflowListGoods);
        }
        Wrapper<TDamageListGoods> wrapper = new EntityWrapper<TDamageListGoods>();
        wrapper.eq("damage_list_id",id);
        List<TDamageListGoods> tDamageListGoods = tDamageListGoodsServiceImpl.selectList(wrapper);
        return ResultEntity.ok(tDamageListGoods);
    }

    //查询单据的类型
    @RequestMapping("/orderType")
    public ResultEntity orderType(){
        List<TDo> list = tDoServiceImpl.selectType();
        return ResultEntity.ok(list);
    }
}
